package com.itheima.reggie.controller;

import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.Dish;
import com.itheima.reggie.entity.DishDto;
import com.itheima.reggie.service.DishService;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dish")
public class DishController {

    @Autowired(required = false)
    private DishService dishService;

    @GetMapping("/list")
    public R<List<DishDto>> list(Long categoryId,Integer status) {
        List<DishDto> dishDtoList = dishService.findByCategoryId(categoryId,status);
        return R.success(dishDtoList);
    }

    @DeleteMapping
    public R<String> deleteByIds(@RequestParam("ids") List<Long> ids) {
        dishService.deletByIds(ids);
        return R.success("删除成功");
    }

    @PostMapping("/status/{status}")
    public R<String> status(@PathVariable Integer status,@RequestParam("ids") List<Long> ids) {
        dishService.setStatus(status, ids);
        return R.success("状态修改成功");
    }



}
